<?php

/**
 * This is the model class for table "personal_information".
 *
 * The followings are the available columns in table 'personal_information':
 * @property integer $id
 * @property string $date_time
 * @property string $fname
 * @property string $lname
 * @property string $mi
 * @property string $b_date
 * @property integer $age
 * @property string $gender
 * @property string $email
 * @property integer $address_no
 * @property string $add_street
 * @property string $add_city
 * @property string $country
 * @property integer $zip
 * @property integer $home_tel
 * @property integer $work_tel
 * @property integer $cellno
 * @property string $company
 * @property string $work
 * @property integer $heathinsurance_id
 * @property integer $inventory_id
 *
 * The followings are the available model relations:
 * @property FamilyHistory[] $familyHistories
 * @property MedicalHistory[] $medicalHistories
 * @property HealthInsurance $heathinsurance
 * @property Inventory $inventory
 * @property ReviewSystems[] $reviewSystems
 * @property Rx[] $rxes
 * @property Socialhistory[] $socialhistories
 */
class PersonalInformation extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return PersonalInformation the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'personal_information';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('date_time, fname, lname, mi, b_date, age, gender, email, address_no, add_street, add_city, country, zip', 'required'),
			array('age, address_no, zip, home_tel, work_tel, cellno, heathinsurance_id, inventory_id', 'numerical', 'integerOnly'=>true),
			array('fname, lname, email, add_street, company, work', 'length', 'max'=>45),
			array('mi', 'length', 'max'=>2),
			array('gender', 'length', 'max'=>8),
			array('add_city, country', 'length', 'max'=>30),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, date_time, fname, lname, mi, b_date, age, gender, email, address_no, add_street, add_city, country, zip, home_tel, work_tel, cellno, company, work, heathinsurance_id, inventory_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'familyHistories' => array(self::HAS_MANY, 'FamilyHistory', 'personalinfo_id'),
			'medicalHistories' => array(self::HAS_MANY, 'MedicalHistory', 'personalinfo_id'),
			'heathinsurance' => array(self::BELONGS_TO, 'HealthInsurance', 'heathinsurance_id'),
			'inventory' => array(self::BELONGS_TO, 'Inventory', 'inventory_id'),
			'reviewSystems' => array(self::HAS_MANY, 'ReviewSystems', 'personalinfo_id'),
			'rxes' => array(self::HAS_MANY, 'Rx', 'personalinfo_id'),
			'socialhistories' => array(self::HAS_MANY, 'Socialhistory', 'personalinfo_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'date_time' => 'Date Time',
			'fname' => 'Fname',
			'lname' => 'Lname',
			'mi' => 'Mi',
			'b_date' => 'B Date',
			'age' => 'Age',
			'gender' => 'Gender',
			'email' => 'Email',
			'address_no' => 'Address No',
			'add_street' => 'Add Street',
			'add_city' => 'Add City',
			'country' => 'Country',
			'zip' => 'Zip',
			'home_tel' => 'Home Tel',
			'work_tel' => 'Work Tel',
			'cellno' => 'Cellno',
			'company' => 'Company',
			'work' => 'Work',
			'heathinsurance_id' => 'Heathinsurance',
			'inventory_id' => 'Inventory',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('date_time',$this->date_time,true);
		$criteria->compare('fname',$this->fname,true);
		$criteria->compare('lname',$this->lname,true);
		$criteria->compare('mi',$this->mi,true);
		$criteria->compare('b_date',$this->b_date,true);
		$criteria->compare('age',$this->age);
		$criteria->compare('gender',$this->gender,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('address_no',$this->address_no);
		$criteria->compare('add_street',$this->add_street,true);
		$criteria->compare('add_city',$this->add_city,true);
		$criteria->compare('country',$this->country,true);
		$criteria->compare('zip',$this->zip);
		$criteria->compare('home_tel',$this->home_tel);
		$criteria->compare('work_tel',$this->work_tel);
		$criteria->compare('cellno',$this->cellno);
		$criteria->compare('company',$this->company,true);
		$criteria->compare('work',$this->work,true);
		$criteria->compare('heathinsurance_id',$this->heathinsurance_id);
		$criteria->compare('inventory_id',$this->inventory_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}